package com.example.config.datasource;

import lombok.extern.slf4j.Slf4j;

/**
 * @Author ZHAO Yudong
 * @Date 2021/12/9 16:50
 * @description：
 */
@Slf4j  //操作数据源
public class DynamicDataSourceSwitcher {

    public static final String Mater = "master";
    public static final String Slave1 = "slave1";

    private static final ThreadLocal<String> contextHolder = new ThreadLocal<>();

    public static void setDataSource(String name){
        log.info("-------- 设置数据源数据源为 ：{} ", name);
        contextHolder.set(name);
    }

    public static String getDataSource(){
        return contextHolder.get();
    }

    public static void cleanDataSource(){
        contextHolder.remove();
    }

}

